﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class shop_Member_Manager : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            Utility.InitUltraWebGrid.InitDisplayLayOut(this.UWGMember);

            if (_Site != null)
            {
                hSiteID.Text = _Customer.ShopID.ToString();
                hCustomerID.Text = _Customer.ID.ToString();
                hCustomerTypeID.Text = _Customer.CustomerTypeID.ToString();
            }
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        //RequestCompetences = Competences.BuildCompetencesList(Competences.Member_Manager);//页面权限

        base.OnLoad(e);
    }

    #endregion

    protected void btnDetail_Click(object sender, EventArgs e)
    {
        Response.Redirect("Member_Detail.aspx?customerID=" + customerID.Value);
    }

    protected void btnStart_Click(object sender, EventArgs e)
    {
        long ID = Shove._Convert.StrToLong(customerID.Value, 0);
        DAL.Tables.tbl_Customer table = new DAL.Tables.tbl_Customer();
        table.Status.Value = 1;

        if (table.Update("[ID]=" + ID) > 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "会员已成功开放");
        }

        BindData();
    }

    protected void btnStop_Click(object sender, EventArgs e)
    {
        long ID = Shove._Convert.StrToLong(customerID.Value, 0);
        DAL.Tables.tbl_Customer table = new DAL.Tables.tbl_Customer();
        table.Status.Value = 3;

        if (table.Update("[ID]=" + ID) > 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "会员已成功禁用");
        }

        BindData();
    }

    protected void UWGMember_PageIndexChanged(object sender, Infragistics.WebUI.UltraWebGrid.PageEventArgs e)
    {
        BindData();
    }

    private void BindData()
    {
        long SiteID = Shove._Convert.StrToLong(hSiteID.Text, 0);
        long CustomerID = Shove._Convert.StrToLong(hCustomerID.Text, 0);
        int CustomerTypeID = Shove._Convert.StrToInt(hCustomerTypeID.Text,0);

        string Condition = "RegisterShopID=" + SiteID + " and CustomerTypeID > 10";

        if (CustomerTypeID == 0 || CustomerID == 1)
        {
            Condition = "CustomerTypeID > 10";
        }

        DataTable dt =  new DAL.Views.V_Customer().Open("", Condition, "");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "暂无您所需要的数据", this.GetType().BaseType.FullName);

            return;
        }

        this.UWGMember.DataSource = dt;
        this.UWGMember.DataBind();
    }

}
